<?php
namespace Home\Controller;
use Think\Controller;
class InterfaceController extends Controller {

    //获取用户openid
    public function Get_Openid(){
        $appid = 'wx53d35d56d39587c2';
        $secret = '2546b893b238ff0ee24e014039d1f58b';
        $code = I('get.code'); 
        $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appid}&secret={$secret}&js_code={$code}&grant_type=authorization_code";
        $curl = curl_init($url);
        curl_setopt($curl,CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($curl,CURLOPT_RETURNTRANSFER, true);
        $o = curl_exec($curl);
        echo $o;
    }


    //更新用户登陆信息
   //获取用户openid 并更新用户信息
    public function User_Login(){
        if(!I('get.openid')){
            exit;
        }
        $data['users_name'] = I('get.users_name');
        $data['users_head'] = I('get.users_head');
        $data['users_openid'] = I('get.openid');

        $cls_User = new UsersModelController();
        $data = $cls_User->update_or_add($data);
    }



	//分页获取相册
    public function get_album_all(){
    	$cls_Album = new AlbumModelController();
    	$data = $cls_Album->get_album_all();
      //  dump($data);
        if(count($data)>0){
    	   echo json_encode($data);
        }else{
            echo $data;
        }
    }


    //搜索相册
    public function get_album_search(){
    	$cls_Album = new AlbumModelController();
    	$data = $cls_Album->get_album_search(I('get.album_name'));
    	echo json_encode($data);
    }



 


    //更新收藏
    public function set_collect(){
        $aid = I('get.aid');
        $openid = I('get.openid');  //通过code获取openid
        $cls_Collect = new CollectModelController();
        echo $cls_Collect->update_collect($openid,$aid);
    }


    //更新点赞数
    public function set_flower(){
        $aid = I('get.aid');
        $openid = I('get.openid');  //通过code获取openid
        $cls_flower = new FlowerModelController();
        echo $cls_flower->update_flower($openid,$aid);
    }


    //获取用户收藏的相册id
    public function get_collect_all(){
        $openid = I('get.openid');
        $cls_Collect = new CollectModelController();
        $data = $cls_Collect->get_collect_all($openid);
        if($data){
            echo $data['collect_aids'];
        }
       // echo 111111;
    }



    //分页获取相册中的图片
    public function get_album_pics(){
      //  echo 333333;exit;
        $aid = I('get.aid');
        $cls_Imgs = new ImgsModelController();
        $data = $cls_Imgs->get_album_pics($aid);
        if($data){
            echo json_encode($data);
        }
    }


     //根据指定相册的全部图片
    public function get_album_pics_all(){
        $aid = I('get.aid');
        $cls_Imgs = new ImgsModelController();
        $data = $cls_Imgs->get_album_pics_all($aid);
        if($data){
            echo json_encode($data);
        }
    }


    //获取相册的赞和收藏数
    public function get_flower_collect(){
        $aid = I('get.aid');
        $field = I('get.field');
        if(!$aid || !$field){
            exit;
        }
        $cls_Album = new AlbumModelController();
        $data = $cls_Album->get_album_info($aid,$field);
        if($data){
            echo json_encode($data);
        }
    }





    //获取用户的所有赞和收藏数
    public function get_user_flower_collect(){
        $openid = I('get.openid');
        $cls_Collect = new CollectModelController();
        $Res_Collect = $cls_Collect->get_collect_all($openid);
        $data['Collect_Aids'] = json_decode($Res_Collect['collect_aids']);
        $cls_Flower = new FlowerModelController();
        $Res_Flower = $cls_Flower->get_flower_all($openid);
        $data['Flower_Aids'] = json_decode($Res_Flower['flower_aids']);
        echo json_encode($data);
    }



    //获取用户收藏的相册
    public function Get_Collect_Albums(){
        $aids = I('get.aids');

        $cls_Album = new AlbumModelController();
        $data = $cls_Album->get_info($aids);
        if($data){
            echo json_encode($data);
        }
    }




    //获取指定相册的点赞数
    public function Get_Album_Flowers(){
        $aid = I('get.aid');
        $field = "album_flower";
        $cls_Album = new AlbumModelController();
        $data = $cls_Album->get_album_info($aid,$field);
        echo $data['album_flower'];

    }



}
